home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-05 / driverss.zip / PKTMODE.ASM < prev    next >
Assembly Source File  |  1991-03-25  |  5KB  |  223 lines

  1. version    equ    1
  2.  
  3. ;  Russell Nelson, Clarkson University.  September 14, 1989
  4. ;  Copyright, 1989, Russell Nelson
  5.  
  6. ;   This program is free software; you can redistribute it and/or modify
  7. ;   it under the terms of the GNU General Public License as published by
  8. ;   the Free Software Foundation, version 1.
  9. ;
  10. ;   This program is distributed in the hope that it will be useful,
  11. ;   but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ;   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. ;   GNU General Public License for more details.
  14. ;
  15. ;   You should have received a copy of the GNU General Public License
  16. ;   along with this program; if not, write to the Free Software
  17. ;   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  
  19.     include    defs.asm
  20.  
  21. code    segment word public
  22.     assume    cs:code, ds:code
  23.  
  24.     org    80h
  25. phd_dioa    label    byte
  26.  
  27.     org    100h
  28. start:
  29.     jmp    start_1
  30.  
  31. copyleft_msg    label    byte
  32.  db "Packet mode version ",'0'+majver,".",'0'+version," copyright 1990, Russell Nelson.",CR,LF
  33.  db "This program is free software; see the file COPYING for details.",CR,LF
  34.  db "NO WARRANTY; see the file COPYING for details.",CR,LF
  35. crlf_msg    db    CR,LF,'$'
  36.  
  37. int_pkt    macro
  38.     pushf
  39.     cli
  40.     call    their_isr
  41.     endm
  42.  
  43. their_isr    dd    ?
  44. packet_int_no    db    ?,?,?,?
  45. packet_mode    dw    -1,?
  46.  
  47. handle        dw    0
  48. this_mode    dw    ?
  49. bogus_type    db    0,0        ;totally bogus type code.
  50.  
  51. signature    db    'PKT DRVR',0
  52. signature_len    equ    $-signature
  53. no_signature_msg    db    "No packet driver at that address",'$'
  54. usage_msg    db    "usage: pktmode <packet_int_no> [<mode>]",'$'
  55. bad_handle_msg    db    "Bad handle error",'$'
  56. bad_mode_msg    db    "Bad mode error",'$'
  57. bad_error_msg    db    "Unknown error",'$'
  58.  
  59. not_implemented    db    "xx ",'$'
  60. current_mode    db    "-> ",'$'
  61. two_spaces    db    "   ",'$'
  62.  
  63. mode_names    dw    mode_1_msg,mode_2_msg,mode_3_msg,mode_4_msg
  64.         dw    mode_5_msg,mode_6_msg
  65.  
  66. mode_1_msg    db    "1) Turn off receiver",CR,LF,'$'
  67. mode_2_msg    db    "2) Receive only packets sent to this interface",CR,LF,'$'
  68. mode_3_msg    db    "3) Mode 2 plus broadcast",CR,LF,'$'
  69. mode_4_msg    db    "4) Mode 3 plus limited multicast",CR,LF,'$'
  70. mode_5_msg    db    "5) Mode 3 plus all multicast",CR,LF,'$'
  71. mode_6_msg    db    "6) All packets",CR,LF,'$'
  72.  
  73.  
  74. usage_error:
  75.     mov    dx,offset usage_msg
  76. error:
  77.     mov    ah,9
  78.     int    21h
  79.     jmp    all_done
  80.  
  81. start_1:
  82.     cld
  83.  
  84.     mov    dx,offset copyleft_msg
  85.     mov    ah,9
  86.     int    21h
  87.  
  88.     mov    si,offset phd_dioa+1
  89.     cmp    byte ptr [si],CR    ;end of line?
  90.     je    usage_error
  91.  
  92.     mov    di,offset packet_int_no
  93.     call    get_number
  94.     mov    di,offset packet_mode
  95.     call    get_number
  96.  
  97.     mov    ah,35h            ;get their packet interrupt.
  98.     mov    al,packet_int_no
  99.     int    21h
  100.     mov    their_isr.offs,bx
  101.     mov    their_isr.segm,es
  102.  
  103.     lea    di,3[bx]
  104.     mov    si,offset signature
  105.     mov    cx,signature_len
  106.     repe    cmpsb
  107.     je    signature_ok
  108.     mov    dx,offset no_signature_msg
  109.     jmp    error
  110. bad_j_1:
  111.     jmp    bad
  112. signature_ok:
  113.  
  114.     push    ds
  115.     mov    ax,1ffh            ;driver_info
  116.     int_pkt
  117.     pop    ds
  118.     call    fatal_error
  119.  
  120.     mov    ah,2            ;access all packets.
  121.     mov    al,ch            ;their class from driver_info().
  122.     mov    bx,dx            ;their type from driver_info().
  123.     mov    dl,cl            ;their number from driver_info().
  124.     mov    cx,2            ;use a type length of 2.
  125.     mov    si,offset bogus_type
  126.     push    cs            ;es:di -> our receiver.
  127.     pop    es
  128.     mov    di,offset our_recv
  129.     int_pkt
  130.     call    fatal_error
  131.     mov    handle,ax
  132.  
  133.     mov    cx,packet_mode
  134.     cmp    cx,-1
  135.     je    get_mode
  136.  
  137.     mov    ah,20            ;set the receive mode.
  138.     mov    bx,handle
  139.     int_pkt
  140.     jc    bad_j_1
  141.     jmp    okay
  142. get_mode:
  143.     mov    ah,21            ;get the receive mode.
  144.     mov    bx,handle
  145.     int_pkt
  146.     jc    bad
  147.     mov    packet_mode,ax
  148.  
  149.     mov    this_mode,1        ;start trying with mode 1.
  150. try_mode:
  151.     cmp    this_mode,6        ;have we hit the last mode?
  152.     ja    no_more_modes        ;yes.
  153.  
  154.     mov    ah,20            ;set the receive mode.
  155.     mov    bx,handle
  156.     mov    cx,this_mode
  157.     int_pkt
  158.     mov    dx,offset not_implemented
  159.     jc    tried_mode        ;we tried it, and it didn't work.
  160.     mov    dx,offset current_mode
  161.     mov    cx,this_mode        ;is this the current mode?
  162.     cmp    packet_mode,cx
  163.     je    tried_mode
  164.     mov    dx,offset two_spaces
  165. tried_mode:
  166.     mov    ah,9            ;print either "  ", "xx", or "->"
  167.     int    21h
  168.  
  169.     mov    bx,this_mode        ;print the name of this mode.
  170.     shl    bx,1
  171.     mov    ah,9
  172.     mov    dx,mode_names[bx-2]
  173.     int    21h
  174.  
  175.     inc    this_mode        ;try the next mode.
  176.     jmp    try_mode
  177.  
  178. no_more_modes:
  179.  
  180.     mov    ah,20            ;set the receive mode.
  181.     mov    bx,handle
  182.     mov    cx,packet_mode
  183.     int_pkt
  184.  
  185. all_done:
  186.     xor    bx,bx            ;only release the handle once.
  187.     xchg    bx,handle
  188.     or    bx,bx
  189.     je    all_done_1        ;we've already released it.
  190.     mov    ah,3            ;release_type
  191.     int_pkt
  192.     jc    bad
  193. all_done_1:
  194.     int    20h
  195.  
  196. bad:
  197.     call    print_error
  198. okay:
  199.     jmp    all_done
  200.  
  201.  
  202. our_recv:
  203.     or    ax,ax            ;first or second call?
  204.     jne    our_recv_1        ;second -- we ignore the packet
  205.     push    cs
  206.     pop    es
  207.     mov    di,offset our_buffer
  208. our_recv_1:
  209.     db    0cbh            ;masm 4.0 doesn't grok "retf"
  210.  
  211.  
  212.     include    getnum.asm
  213.     include    skipblk.asm
  214.     include    getdig.asm
  215.     include    pkterr.asm
  216.     include    chrout.asm
  217.  
  218. our_buffer    label    byte
  219.  
  220. code    ends
  221.  
  222.     end    start
  223.